<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;
class MailController extends Controller
{

    /**
     * @param Request $request
     * @param email 收件人地址
     * @param subject 邮件主题
     * @param data array 模板变量数组
     * @param attachment_path string 附件地址
     * @return bool
     */
    public function send(Request $request)
    {
        $email = $request->get('email');
        $subject = $request->get('subject');
        $data = $request->get('data');
        $attachment_path = $request->get('attachment_path');
        $flag = Mail::send('email.active',['data'=>$data],function($message) use ($email,$subject, $attachment_path){
            $message ->to($email)->subject($subject);
            if(!empty($attachment_path))
            {
                $message ->attach($attachment_path);
            }
        });
        return $flag ? true : false;
    }
}
